package mybatis;

import com.fasterxml.jackson.annotation.JsonIgnore;
import io.swagger.annotations.ApiModelProperty;
import lombok.*;
import mybatis.interfaces.*;

import java.util.List;
import java.util.Map;

/**
 * 查询条件，具体支持哪些查询语法由具体的接口定义
 * <p>
 * 备注：依赖 Sprint-MVC 对URL参数中 [], 的解析
 * </p>
 * 使用示例：
 * <pre>
 * public class UserController {
 *
 *     &#64;ApiOperation(value = "查询用户")
 *     &#64;GetMapping(path= "/users")
 *     public RestResult&lt;PageResponse&lt;User&gt;&gt; query(QueryCondition queryCondition) {
 *         PageResponse&lt;User&gt; users = userService.query(queryCondition)
 *         return RestResult.success(users);
 *     }
 * }
 * </pre>
 *
 * @author CKC
 */
@NoArgsConstructor
@Builder(toBuilder = true)
@AllArgsConstructor(access = AccessLevel.PROTECTED)
@Data
public class QueryCondition implements IFieldQueryCondition,
        ISearchQueryCondition,
        ISearchOrQueryCondition,
        ISearchAndQueryCondition,
        ISearchLeftQueryCondition,
        ISearchRightQueryCondition,
        IFilterQueryCondition,
        IFilterOrQueryCondition,
        INotEqualsQueryCondition,
        ILessThanQueryCondition,
        ILessThanOrEqualsQueryCondition,
        IGreaterThanQueryCondition,
        IGreaterThanOrEqualsQueryCondition,
        ISortQueryCondition,
        IPageQueryCondition {

    private static final long serialVersionUID = -282683469505876661L;

    @ApiModelProperty(name = "fields[?]", value = "需要返回的字段，可过滤嵌套的字段，eg：fields[users]=id,name 表示 仅返回用户对象的id,name")
    @JsonIgnore
    private final transient String fieldsSwaggerView = null;
    protected Map<String, List<String>> fields;

    @ApiModelProperty(name = "search[?]", value = "模糊查询,仅支持不同字段and连接,不支持id的模糊查询，eg: search[name]=name1 表示 name like '%name1%' ")
    @JsonIgnore
    private final transient String searchSwaggerView = null;
    protected Map<String, String> search;

    @ApiModelProperty(name = "searchL[?]", value = "左模糊查询,仅支持不同字段and连接,不支持id的模糊查询，eg: searchL[name]=name1 表示 name like '%name1' ")
    @JsonIgnore
    private final transient String searchLSwaggerView = null;
    protected Map<String, String> searchL;

    @ApiModelProperty(name = "searchR[?]", value = "右模糊查询,仅支持不同字段and连接,不支持id的模糊查询，eg: searchR[name]=name1 表示 name like 'name1%' ")
    @JsonIgnore
    private final transient String searchRSwaggerView = null;
    protected Map<String, String> searchR;

    @ApiModelProperty(name = "searchOr[?]", value = "模糊查询，逻辑或连接,仅支持不同字段OR连接,不支持id的模糊查询，eg: searchOr[type]=enum1&searchOr[name]=name1 表示 type like '%enum1%' or name like '%name1%' ")
    @JsonIgnore
    private final transient String searchOrSwaggerView = null;
    protected Map<String, String> searchOr;

    @ApiModelProperty(name = "searchAnd[?]", value = "模糊查询，逻辑或连接,仅支持不同字段And连接,不支持id的模糊查询，eg: searchAnd[type]=enum1&searchAnd[name]=name1 表示 type like '%enum1%' and name like '%name1%' ")
    @JsonIgnore
    private final transient String searchAndSwaggerView = null;
    protected Map<String, String> searchAnd;

    @ApiModelProperty(name = "filter[?]", value = "等于，相同字段or，不同字段and，eg: filter[type]=user&filter[type]=userGroup&filter[name]=name1 表示 (type = 'userGroup' or type = 'user') and name = 'name1' ")
    @JsonIgnore
    private final transient String filterSwaggerView = null;
    protected Map<String, List<String>> filter;

    @ApiModelProperty(name = "filterOr[?]", value = "等于，逻辑或连接，相同字段or，不同字段or，eg: filterOr[type]=user&filterOr[type]=userGroup&filterOr[name]=name1 表示 (type = 'userGroup' or type = 'user') or name = 'name1' ")
    @JsonIgnore
    private final transient String filterOrSwaggerView = null;
    protected Map<String, List<String>> filterOr;

    @ApiModelProperty(name = "neq[?]", value = "不相等,相同字段and,不同字段and，eg: neq[type]=user&neq[type]=userGroup&neq[name]=name 表示 (type <> 'userGroup' and type <> 'user') and name <> 'name1' ")
    @JsonIgnore
    private final transient String neqSwaggerView = null;
    protected Map<String, List<String>> neq;

    @ApiModelProperty(name = "lt[?]", value = "小于,仅支持不同字段and连接，eg: lt[age]=20 表示 age < 20 ")
    @JsonIgnore
    private final transient String ltSwaggerView = null;
    protected Map<String, String> lt;

    @ApiModelProperty(name = "lte[?]", value = "小于等于,仅支持不同字段and连接，eg: lte[age]=20 表示 age <= 20 ")
    @JsonIgnore
    private final transient String lteSwaggerView = null;
    protected Map<String, String> lte;

    @ApiModelProperty(name = "gt[?]", value = "大于, 仅支持不同字段and连接，eg: gt[age]=20 表示 age > 20 ")
    @JsonIgnore
    private final transient String gtSwaggerView = null;
    protected Map<String, String> gt;

    @ApiModelProperty(name = "gte[?]", value = "大于等于，仅支持不同字段and连接，eg: gte[age]=20 表示 age >= 20 ")
    @JsonIgnore
    private final transient String gteSwaggerView = null;
    protected Map<String, String> gte;

    @ApiModelProperty(name = "sort", value = "排序，eg1: sort=-name,-age 表示 按照name的倒叙和age倒叙排序；eg2: sort=-name,age 表示 按照name的倒叙和age升序排序")
    private List<String> sort;

    @ApiModelProperty(name = "page[?]", value = "分页查询，current 页码，从1开始, 大于0，缺省1; size 一页的大小，大于0, 缺省10，最大1000; 例如: page[current]=1&page[size]=5 表示 取 第1页的5条数据的数据")
    @JsonIgnore
    private final transient String pageSwaggerView = null;
    protected Map<String, Integer> page;
}
